package com.yunti.springboot.vo.res;

import com.yunti.springboot.po.Score;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

/**
 * @author yangtt
 * @date 2023/12/29
 */
@Data
public class FinalScore {
    private Integer id;

    /** 次数 | 表字段 count */
    private Integer count;

    /**  | 表字段 raw_score */
    private String rawScore;

    /**  | 表字段 conversion_score */
    private BigDecimal conversionScore;

    private Integer itemNo;

    /** 学生id | 表字段 stu_id */
    private Integer stuId;

    /** 学生id | 表字段 stu_id */
    private Integer subId;

    /** 报考科目详情 | 表字段 elective_id */
    private Integer electiveId;



    public void setScoreList(List<Score> scoreList) {
        scoreList.stream().max(new Comparator<Score>() {
            @Override
            public int compare(Score o1, Score o2) {
                Double score1 = Double.MIN_NORMAL;
                Double score2 = Double.MIN_NORMAL;
                if(o1.getConversionScore()!=null){
                    score1 = o1.getConversionScore().doubleValue();
                }
                if(o2.getConversionScore()!=null){
                    score2 = o2.getConversionScore().doubleValue();
                }
                return Double.compare(score1, score2);
            }
        }).ifPresent(finalScore -> {
            this.id = finalScore.getId();
            this.count = finalScore.getCount();
            this.rawScore = finalScore.getRawScore();
            this.conversionScore = finalScore.getConversionScore();
            this.itemNo = finalScore.getItemNo();
            this.stuId = finalScore.getStuId();
            this.subId = finalScore.getSubId();
            this.electiveId = finalScore.getElectiveId();
        });
    }
}
